use keyboard_types::Code;
pub use keyboard_types::{
    Key,
    Modifiers,
};

// Return the equivalent of Winit `ModifiersState` in keyboard_types
pub fn map_winit_modifiers(modifiers: winit::keyboard::ModifiersState) -> Modifiers {
    let mut new_modifiers = Modifiers::empty();
    if modifiers.alt_key() {
        new_modifiers.toggle(Modifiers::ALT);
    }
    if modifiers.control_key() {
        new_modifiers.toggle(Modifiers::CONTROL);
    }
    if modifiers.shift_key() {
        new_modifiers.toggle(Modifiers::SHIFT);
    }
    if modifiers.super_key() {
        new_modifiers.toggle(Modifiers::META);
    }
    new_modifiers
}

/// Return the equivalent Winit's `Key` in keyboard_types
pub fn map_winit_key(key: &winit::keyboard::Key) -> Key {
    match key {
        winit::keyboard::Key::Character(c) => Key::Character(c.to_string()),
        winit::keyboard::Key::Named(named_key) => match named_key {
            winit::keyboard::NamedKey::Space => Key::Character(" ".to_string()),
            winit::keyboard::NamedKey::Delete => Key::Delete,
            winit::keyboard::NamedKey::Backspace => Key::Backspace,
            winit::keyboard::NamedKey::ArrowDown => Key::ArrowDown,
            winit::keyboard::NamedKey::ArrowLeft => Key::ArrowLeft,
            winit::keyboard::NamedKey::ArrowRight => Key::ArrowRight,
            winit::keyboard::NamedKey::ArrowUp => Key::ArrowUp,
            winit::keyboard::NamedKey::End => Key::End,
            winit::keyboard::NamedKey::Home => Key::Home,
            winit::keyboard::NamedKey::PageDown => Key::PageDown,
            winit::keyboard::NamedKey::PageUp => Key::PageUp,
            winit::keyboard::NamedKey::Tab => Key::Tab,
            winit::keyboard::NamedKey::Enter => Key::Enter,
            winit::keyboard::NamedKey::Escape => Key::Escape,
            winit::keyboard::NamedKey::F1 => Key::F1,
            winit::keyboard::NamedKey::F2 => Key::F2,
            winit::keyboard::NamedKey::F3 => Key::F3,
            winit::keyboard::NamedKey::F4 => Key::F4,
            winit::keyboard::NamedKey::F5 => Key::F5,
            winit::keyboard::NamedKey::F6 => Key::F6,
            winit::keyboard::NamedKey::F7 => Key::F7,
            winit::keyboard::NamedKey::F8 => Key::F8,
            winit::keyboard::NamedKey::F9 => Key::F9,
            winit::keyboard::NamedKey::F10 => Key::F10,
            winit::keyboard::NamedKey::F11 => Key::F11,
            winit::keyboard::NamedKey::F12 => Key::F12,
            winit::keyboard::NamedKey::F13 => Key::F13,
            winit::keyboard::NamedKey::F14 => Key::F14,
            winit::keyboard::NamedKey::F15 => Key::F15,
            winit::keyboard::NamedKey::F16 => Key::F16,
            winit::keyboard::NamedKey::F17 => Key::F17,
            winit::keyboard::NamedKey::F18 => Key::F18,
            winit::keyboard::NamedKey::F19 => Key::F19,
            winit::keyboard::NamedKey::F20 => Key::F20,
            winit::keyboard::NamedKey::F21 => Key::F21,
            winit::keyboard::NamedKey::F22 => Key::F22,
            winit::keyboard::NamedKey::F23 => Key::F23,
            winit::keyboard::NamedKey::F24 => Key::F24,
            winit::keyboard::NamedKey::Pause => Key::Pause,
            winit::keyboard::NamedKey::Insert => Key::Insert,
            winit::keyboard::NamedKey::ContextMenu => Key::ContextMenu,
            winit::keyboard::NamedKey::BrowserBack => Key::BrowserBack,
            winit::keyboard::NamedKey::BrowserFavorites => Key::BrowserFavorites,
            winit::keyboard::NamedKey::BrowserForward => Key::BrowserForward,
            winit::keyboard::NamedKey::BrowserHome => Key::BrowserHome,
            winit::keyboard::NamedKey::BrowserRefresh => Key::BrowserRefresh,
            winit::keyboard::NamedKey::BrowserSearch => Key::BrowserSearch,
            winit::keyboard::NamedKey::BrowserStop => Key::BrowserStop,
            winit::keyboard::NamedKey::MediaTrackNext => Key::MediaTrackNext,
            winit::keyboard::NamedKey::MediaPlayPause => Key::MediaPlayPause,
            winit::keyboard::NamedKey::MediaTrackPrevious => Key::MediaTrackPrevious,
            winit::keyboard::NamedKey::MediaStop => Key::MediaStop,
            winit::keyboard::NamedKey::AudioVolumeDown => Key::AudioVolumeDown,
            winit::keyboard::NamedKey::AudioVolumeMute => Key::AudioVolumeMute,
            winit::keyboard::NamedKey::AudioVolumeUp => Key::AudioVolumeUp,
            winit::keyboard::NamedKey::LaunchApplication2 => Key::LaunchApplication2,
            winit::keyboard::NamedKey::LaunchMail => Key::LaunchMail,
            winit::keyboard::NamedKey::Convert => Key::Convert,
            winit::keyboard::NamedKey::Alt => Key::Alt,
            winit::keyboard::NamedKey::AltGraph => Key::AltGraph,
            winit::keyboard::NamedKey::CapsLock => Key::CapsLock,
            winit::keyboard::NamedKey::Control => Key::Control,
            winit::keyboard::NamedKey::Fn => Key::Fn,
            winit::keyboard::NamedKey::FnLock => Key::FnLock,
            winit::keyboard::NamedKey::NumLock => Key::NumLock,
            winit::keyboard::NamedKey::ScrollLock => Key::ScrollLock,
            winit::keyboard::NamedKey::Shift => Key::Shift,
            winit::keyboard::NamedKey::Symbol => Key::Symbol,
            winit::keyboard::NamedKey::SymbolLock => Key::SymbolLock,
            winit::keyboard::NamedKey::Meta => Key::Meta,
            winit::keyboard::NamedKey::Hyper => Key::Hyper,
            winit::keyboard::NamedKey::Super => Key::Super,
            winit::keyboard::NamedKey::Clear => Key::Clear,
            winit::keyboard::NamedKey::Copy => Key::Copy,
            winit::keyboard::NamedKey::CrSel => Key::CrSel,
            winit::keyboard::NamedKey::Cut => Key::Cut,
            winit::keyboard::NamedKey::EraseEof => Key::EraseEof,
            winit::keyboard::NamedKey::ExSel => Key::ExSel,
            winit::keyboard::NamedKey::Paste => Key::Paste,
            winit::keyboard::NamedKey::Redo => Key::Redo,
            winit::keyboard::NamedKey::Undo => Key::Undo,
            winit::keyboard::NamedKey::Accept => Key::Accept,
            winit::keyboard::NamedKey::Again => Key::Again,
            winit::keyboard::NamedKey::Attn => Key::Attn,
            winit::keyboard::NamedKey::Cancel => Key::Cancel,
            winit::keyboard::NamedKey::Execute => Key::Execute,
            winit::keyboard::NamedKey::Find => Key::Find,
            winit::keyboard::NamedKey::Help => Key::Help,
            winit::keyboard::NamedKey::Play => Key::Play,
            winit::keyboard::NamedKey::Props => Key::Props,
            winit::keyboard::NamedKey::Select => Key::Select,
            winit::keyboard::NamedKey::ZoomIn => Key::ZoomIn,
            winit::keyboard::NamedKey::ZoomOut => Key::ZoomOut,
            winit::keyboard::NamedKey::BrightnessDown => Key::BrightnessDown,
            winit::keyboard::NamedKey::BrightnessUp => Key::BrightnessUp,
            winit::keyboard::NamedKey::Eject => Key::Eject,
            winit::keyboard::NamedKey::LogOff => Key::LogOff,
            winit::keyboard::NamedKey::Power => Key::Power,
            winit::keyboard::NamedKey::PowerOff => Key::PowerOff,
            winit::keyboard::NamedKey::PrintScreen => Key::PrintScreen,
            winit::keyboard::NamedKey::Hibernate => Key::Hibernate,
            winit::keyboard::NamedKey::Standby => Key::Standby,
            winit::keyboard::NamedKey::WakeUp => Key::WakeUp,
            winit::keyboard::NamedKey::AllCandidates => Key::AllCandidates,
            winit::keyboard::NamedKey::Alphanumeric => Key::Alphanumeric,
            winit::keyboard::NamedKey::CodeInput => Key::CodeInput,
            winit::keyboard::NamedKey::Compose => Key::Compose,
            winit::keyboard::NamedKey::FinalMode => Key::FinalMode,
            winit::keyboard::NamedKey::GroupFirst => Key::GroupFirst,
            winit::keyboard::NamedKey::GroupLast => Key::GroupLast,
            winit::keyboard::NamedKey::GroupNext => Key::GroupNext,
            winit::keyboard::NamedKey::GroupPrevious => Key::GroupPrevious,
            winit::keyboard::NamedKey::ModeChange => Key::ModeChange,
            winit::keyboard::NamedKey::NextCandidate => Key::NextCandidate,
            winit::keyboard::NamedKey::NonConvert => Key::NonConvert,
            winit::keyboard::NamedKey::PreviousCandidate => Key::PreviousCandidate,
            winit::keyboard::NamedKey::Process => Key::Process,
            winit::keyboard::NamedKey::SingleCandidate => Key::SingleCandidate,
            winit::keyboard::NamedKey::HangulMode => Key::HangulMode,
            winit::keyboard::NamedKey::HanjaMode => Key::HanjaMode,
            winit::keyboard::NamedKey::JunjaMode => Key::JunjaMode,
            winit::keyboard::NamedKey::Eisu => Key::Eisu,
            winit::keyboard::NamedKey::Hankaku => Key::Hankaku,
            winit::keyboard::NamedKey::Hiragana => Key::Hiragana,
            winit::keyboard::NamedKey::HiraganaKatakana => Key::HiraganaKatakana,
            winit::keyboard::NamedKey::KanaMode => Key::KanaMode,
            winit::keyboard::NamedKey::KanjiMode => Key::KanjiMode,
            winit::keyboard::NamedKey::Katakana => Key::Katakana,
            winit::keyboard::NamedKey::Romaji => Key::Romaji,
            winit::keyboard::NamedKey::Zenkaku => Key::Zenkaku,
            winit::keyboard::NamedKey::ZenkakuHankaku => Key::ZenkakuHankaku,
            winit::keyboard::NamedKey::Soft1 => Key::Soft1,
            winit::keyboard::NamedKey::Soft2 => Key::Soft2,
            winit::keyboard::NamedKey::Soft3 => Key::Soft3,
            winit::keyboard::NamedKey::Soft4 => Key::Soft4,
            winit::keyboard::NamedKey::ChannelDown => Key::ChannelDown,
            winit::keyboard::NamedKey::ChannelUp => Key::ChannelUp,
            winit::keyboard::NamedKey::Close => Key::Close,
            winit::keyboard::NamedKey::MailForward => Key::MailForward,
            winit::keyboard::NamedKey::MailReply => Key::MailReply,
            winit::keyboard::NamedKey::MailSend => Key::MailSend,
            winit::keyboard::NamedKey::MediaClose => Key::MediaClose,
            winit::keyboard::NamedKey::MediaFastForward => Key::MediaFastForward,
            winit::keyboard::NamedKey::MediaPause => Key::MediaPause,
            winit::keyboard::NamedKey::MediaPlay => Key::MediaPlay,
            winit::keyboard::NamedKey::MediaRecord => Key::MediaRecord,
            _ => Key::Unidentified,
        },
        _ => Key::Unidentified,
    }
}

/// Return the equivalent of Winit's `PhysicalKey` in keyboard_types
pub fn map_winit_physical_key(key: &winit::keyboard::PhysicalKey) -> Code {
    if let winit::keyboard::PhysicalKey::Code(key) = key {
        match key {
            winit::keyboard::KeyCode::Digit1 => Code::Digit1,
            winit::keyboard::KeyCode::Digit2 => Code::Digit2,
            winit::keyboard::KeyCode::Digit3 => Code::Digit3,
            winit::keyboard::KeyCode::Digit4 => Code::Digit4,
            winit::keyboard::KeyCode::Digit5 => Code::Digit5,
            winit::keyboard::KeyCode::Digit6 => Code::Digit6,
            winit::keyboard::KeyCode::Digit7 => Code::Digit7,
            winit::keyboard::KeyCode::Digit8 => Code::Digit8,
            winit::keyboard::KeyCode::Digit9 => Code::Digit9,
            winit::keyboard::KeyCode::Digit0 => Code::Digit0,
            winit::keyboard::KeyCode::KeyA => Code::KeyA,
            winit::keyboard::KeyCode::KeyB => Code::KeyB,
            winit::keyboard::KeyCode::KeyC => Code::KeyC,
            winit::keyboard::KeyCode::KeyD => Code::KeyD,
            winit::keyboard::KeyCode::KeyE => Code::KeyE,
            winit::keyboard::KeyCode::KeyF => Code::KeyF,
            winit::keyboard::KeyCode::KeyG => Code::KeyG,
            winit::keyboard::KeyCode::KeyH => Code::KeyH,
            winit::keyboard::KeyCode::KeyI => Code::KeyI,
            winit::keyboard::KeyCode::KeyJ => Code::KeyJ,
            winit::keyboard::KeyCode::KeyK => Code::KeyK,
            winit::keyboard::KeyCode::KeyL => Code::KeyL,
            winit::keyboard::KeyCode::KeyM => Code::KeyM,
            winit::keyboard::KeyCode::KeyN => Code::KeyN,
            winit::keyboard::KeyCode::KeyO => Code::KeyO,
            winit::keyboard::KeyCode::KeyP => Code::KeyP,
            winit::keyboard::KeyCode::KeyQ => Code::KeyQ,
            winit::keyboard::KeyCode::KeyR => Code::KeyR,
            winit::keyboard::KeyCode::KeyS => Code::KeyS,
            winit::keyboard::KeyCode::KeyT => Code::KeyT,
            winit::keyboard::KeyCode::KeyU => Code::KeyU,
            winit::keyboard::KeyCode::KeyV => Code::KeyV,
            winit::keyboard::KeyCode::KeyW => Code::KeyW,
            winit::keyboard::KeyCode::KeyX => Code::KeyX,
            winit::keyboard::KeyCode::KeyY => Code::KeyY,
            winit::keyboard::KeyCode::KeyZ => Code::KeyZ,
            winit::keyboard::KeyCode::Escape => Code::Escape,
            winit::keyboard::KeyCode::F1 => Code::F1,
            winit::keyboard::KeyCode::F2 => Code::F2,
            winit::keyboard::KeyCode::F3 => Code::F3,
            winit::keyboard::KeyCode::F4 => Code::F4,
            winit::keyboard::KeyCode::F5 => Code::F5,
            winit::keyboard::KeyCode::F6 => Code::F6,
            winit::keyboard::KeyCode::F7 => Code::F7,
            winit::keyboard::KeyCode::F8 => Code::F8,
            winit::keyboard::KeyCode::F9 => Code::F9,
            winit::keyboard::KeyCode::F10 => Code::F10,
            winit::keyboard::KeyCode::F11 => Code::F11,
            winit::keyboard::KeyCode::F12 => Code::F12,
            winit::keyboard::KeyCode::F13 => Code::F13,
            winit::keyboard::KeyCode::F14 => Code::F14,
            winit::keyboard::KeyCode::F15 => Code::F15,
            winit::keyboard::KeyCode::F16 => Code::F16,
            winit::keyboard::KeyCode::F17 => Code::F17,
            winit::keyboard::KeyCode::F18 => Code::F18,
            winit::keyboard::KeyCode::F19 => Code::F19,
            winit::keyboard::KeyCode::F20 => Code::F20,
            winit::keyboard::KeyCode::F21 => Code::F21,
            winit::keyboard::KeyCode::F22 => Code::F22,
            winit::keyboard::KeyCode::F23 => Code::F23,
            winit::keyboard::KeyCode::F24 => Code::F24,
            winit::keyboard::KeyCode::Pause => Code::Pause,
            winit::keyboard::KeyCode::Insert => Code::Insert,
            winit::keyboard::KeyCode::Home => Code::Home,
            winit::keyboard::KeyCode::Delete => Code::Delete,
            winit::keyboard::KeyCode::End => Code::End,
            winit::keyboard::KeyCode::PageDown => Code::PageDown,
            winit::keyboard::KeyCode::PageUp => Code::PageUp,
            winit::keyboard::KeyCode::ArrowLeft => Code::ArrowLeft,
            winit::keyboard::KeyCode::ArrowUp => Code::ArrowUp,
            winit::keyboard::KeyCode::ArrowRight => Code::ArrowRight,
            winit::keyboard::KeyCode::ArrowDown => Code::ArrowDown,
            winit::keyboard::KeyCode::Backspace => Code::Backspace,
            winit::keyboard::KeyCode::Enter => Code::Enter,
            winit::keyboard::KeyCode::Space => Code::Space,
            winit::keyboard::KeyCode::NumLock => Code::NumLock,
            winit::keyboard::KeyCode::Numpad0 => Code::Numpad0,
            winit::keyboard::KeyCode::Numpad1 => Code::Numpad1,
            winit::keyboard::KeyCode::Numpad2 => Code::Numpad2,
            winit::keyboard::KeyCode::Numpad3 => Code::Numpad3,
            winit::keyboard::KeyCode::Numpad4 => Code::Numpad4,
            winit::keyboard::KeyCode::Numpad5 => Code::Numpad5,
            winit::keyboard::KeyCode::Numpad6 => Code::Numpad6,
            winit::keyboard::KeyCode::Numpad7 => Code::Numpad7,
            winit::keyboard::KeyCode::Numpad8 => Code::Numpad8,
            winit::keyboard::KeyCode::Numpad9 => Code::Numpad9,
            winit::keyboard::KeyCode::NumpadAdd => Code::NumpadAdd,
            winit::keyboard::KeyCode::NumpadDivide => Code::NumpadDivide,
            winit::keyboard::KeyCode::NumpadDecimal => Code::NumpadDecimal,
            winit::keyboard::KeyCode::NumpadComma => Code::NumpadComma,
            winit::keyboard::KeyCode::NumpadEnter => Code::NumpadEnter,
            winit::keyboard::KeyCode::NumpadEqual => Code::NumpadEqual,
            winit::keyboard::KeyCode::NumpadMultiply => Code::NumpadMultiply,
            winit::keyboard::KeyCode::NumpadSubtract => Code::NumpadSubtract,
            winit::keyboard::KeyCode::Backslash => Code::Backslash,
            winit::keyboard::KeyCode::Comma => Code::Comma,
            winit::keyboard::KeyCode::Convert => Code::Convert,
            winit::keyboard::KeyCode::Equal => Code::Equal,
            winit::keyboard::KeyCode::BracketLeft => Code::BracketLeft,
            winit::keyboard::KeyCode::BracketRight => Code::BracketRight,
            winit::keyboard::KeyCode::ShiftLeft => Code::ShiftLeft,
            winit::keyboard::KeyCode::Meta => Code::MetaLeft,
            winit::keyboard::KeyCode::MediaSelect => Code::MediaSelect,
            winit::keyboard::KeyCode::MediaStop => Code::MediaStop,
            winit::keyboard::KeyCode::Minus => Code::Minus,
            winit::keyboard::KeyCode::Period => Code::Period,
            winit::keyboard::KeyCode::Power => Code::Power,
            winit::keyboard::KeyCode::AltRight => Code::AltRight,
            winit::keyboard::KeyCode::ControlLeft => Code::ControlLeft,
            winit::keyboard::KeyCode::ControlRight => Code::ControlRight,
            winit::keyboard::KeyCode::ShiftRight => Code::ShiftRight,
            winit::keyboard::KeyCode::Semicolon => Code::Semicolon,
            winit::keyboard::KeyCode::Slash => Code::Slash,
            winit::keyboard::KeyCode::Sleep => Code::Sleep,
            winit::keyboard::KeyCode::Tab => Code::Tab,
            winit::keyboard::KeyCode::AudioVolumeUp => Code::AudioVolumeUp,
            winit::keyboard::KeyCode::IntlYen => Code::IntlYen,
            winit::keyboard::KeyCode::Copy => Code::Copy,
            winit::keyboard::KeyCode::Paste => Code::Paste,
            winit::keyboard::KeyCode::Cut => Code::Cut,
            _ => Code::Unidentified,
        }
    } else {
        Code::Unidentified
    }
}
